﻿using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace K9Nano.IM.Areas.Chat.Services
{
    public class AppHttpClient
    {
        private readonly HttpClient _httpClient;

        public AppHttpClient(HttpClient httpClient)
        {
            _httpClient = httpClient;

            _httpClient.Timeout = TimeSpan.FromSeconds(10);
        }

        public async Task<T> GetAsync<T>(string url)
        {
            var body = await _httpClient.GetStreamAsync(url);

            var result = await System.Text.Json.JsonSerializer.DeserializeAsync<T>(body);

            return result;
        }
    }
}